﻿<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:system="clr-namespace:System;assembly=mscorlib"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:converters="clr-namespace:SampleApp.Converters"
    xmlns:controls="clr-namespace:Coding4Fun.Toolkit.Controls;assembly=Coding4Fun.Toolkit.Controls"
    x:Class="SampleApp.Controls.MotorSettingsControl"
	FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    mc:Ignorable="d">
	<UserControl.Resources>
		<converters:IndexToVisibilityConverter x:Name="IntToVis" />
		<converters:MotorValueTimerConverter x:Name="MotorTimerValue" />
		<converters:DoubleRoundedConverter x:Name="RoundValue" />
	</UserControl.Resources>
	<Grid x:Name="LayoutRoot">
		<Rectangle Fill="#ccc" Opacity=".85" />
		<Border Padding="15" Background="#111"  VerticalAlignment="Top">
			<StackPanel>
				<TextBlock
					Foreground="White"
					FontSize="{StaticResource PhoneFontSizeLarge}">
					<Run
						Text="Port " /><Run 
						Text="?" 
						x:Name="PortName" /><Run 
						Text=" - "/><Run 
						Text="?"
						x:Name="ObjectName"/><Run 
						Text=" Settings" />
				</TextBlock>

				<toolkit:ListPicker
					Header="Movement Style"
					Margin="0, 0, 0, 10" 
					x:Name="MovementStyle">
					<system:String>degrees</system:String>
					<system:String>time</system:String>
				</toolkit:ListPicker>

				<Grid>
					<TextBlock 
						HorizontalAlignment="Left">
						<Run Text="Power"/>
					</TextBlock>
					<TextBlock 
						HorizontalAlignment="Right" 
						Text="{Binding Value, ConverterParameter=0, Converter={StaticResource RoundValue}, ElementName=PowerSlider}" />
				</Grid>
				<Slider 
					Margin="0, -10, 0, -30"
					x:Name="PowerSlider"
					Value="0" 
					Minimum="-100"
					Maximum="100"
					SmallChange="1" 
					Foreground="Transparent" />

				<StackPanel 
					Visibility="{Binding SelectedIndex, ConverterParameter=0, Converter={StaticResource IntToVis}, ElementName=MovementStyle}">
					<Grid>
						<TextBlock 
							HorizontalAlignment="Left">
							<Run Text="Degrees"/>
						</TextBlock>
						<TextBlock 
							HorizontalAlignment="Right"
							Text="{Binding Value, ConverterParameter=0, Converter={StaticResource RoundValue}, ElementName=DegreeSlider}" />
					</Grid>
					<Slider 
						Margin="0, -10, 0, -20"
						x:Name="DegreeSlider"
						Value="0" 
						Minimum="0"
						Maximum="720"
						Foreground="Transparent" />
				</StackPanel>

				<StackPanel 
					Visibility="{Binding SelectedIndex, ConverterParameter=1, Converter={StaticResource IntToVis}, ElementName=MovementStyle}">


					<Grid>
						<TextBlock 
							HorizontalAlignment="Left">
							<Run Text="seconds"/>
						</TextBlock>
						<TextBlock 
							HorizontalAlignment="Right"
							Text="{Binding Value, Converter={StaticResource MotorTimerValue}, ElementName=PowerTimerSlider}" />
					</Grid>
					<Slider
						Margin="0, -10, 0, -20"
						x:Name="PowerTimerSlider"
						Value="5" />
				</StackPanel>
				<controls:RoundButton 
					Label="ok" 
					Click="RoundButton_Click" />
			</StackPanel>
		</Border>
	</Grid>
</UserControl>